home *** CD-ROM | disk | FTP | other *** search
- import java.applet.Applet;
- import java.awt.Component;
- import java.awt.Graphics;
- import java.awt.Image;
- import java.awt.MediaTracker;
- import java.awt.image.ImageObserver;
- import java.net.URL;
-
- public class SiteCam extends Applet implements Runnable {
- Image fBrokenImage;
- Thread fThread;
- int fSleep;
- int fImagesToSend;
- int fImagesSent;
- String fErrString;
- boolean fIsSiteCamDoc;
- boolean fDebug;
- boolean fatalErr;
- boolean fGettingFirst = true;
- boolean fSiteProxy = false;
- String fLoadingString;
- URL fURL;
- boolean fAbort = false;
- Image fImage1;
- Image fImage2;
- Image fLastImage;
- boolean fDone = false;
-
- public static void main(String[] args) {
- System.out.println("SiteCam.main");
- }
-
- public void destroy() {
- this.fThread.stop();
- }
-
- public void start() {
- this.fThread.resume();
- }
-
- public void hide() {
- System.out.println("sitecam: hide()");
- if (this.fImagesSent > 0) {
- this.fAbort = true;
- }
-
- System.out.println("sitecam: hide() done");
- }
-
- public void stop() {
- this.fThread.suspend();
- }
-
- public void run() {
- String errStr = "";
-
- try {
- this.GetStreamingImages();
- } catch (Exception e) {
- errStr = "SiteCam: " + ((Throwable)e).toString();
- System.out.println(errStr);
- }
-
- }
-
- public void fatalError(String errString) {
- if (!this.fatalErr) {
- this.fatalErr = true;
-
- try {
- if (this.fErrString == null) {
- this.fErrString = errString;
- } else {
- this.fErrString = this.fErrString + errString;
- }
-
- this.fErrString = this.fErrString + " \n";
- } catch (Exception var2) {
- }
-
- this.fatalErr = false;
- }
-
- }
-
- public void init() {
- this.fErrString = null;
- this.fIsSiteCamDoc = false;
- this.fDebug = false;
- this.fatalErr = false;
- this.fImagesToSend = -1;
- this.fImagesSent = 0;
- String debug = ((Applet)this).getParameter("DEBUG");
- if (debug != null && Integer.parseInt(debug) != 0) {
- this.fDebug = true;
- }
-
- debug = ((Applet)this).getParameter("SITEPROXY");
- if (debug != null && Integer.parseInt(debug) != 0) {
- this.fSiteProxy = true;
- }
-
- String base = null;
- if (((Applet)this).getDocumentBase() != null) {
- base = ((Applet)this).getDocumentBase().toString();
- }
-
- String newBase = base;
- if (base.indexOf(".") != -1) {
- int slash = base.lastIndexOf("/");
- if (slash != -1) {
- newBase = new String(base.getBytes(), 0, slash + 1);
- }
- }
-
- System.out.println("new base " + newBase);
- String fileString = ((Applet)this).getParameter("FILE");
- if (fileString == null) {
- String docString = null;
- docString = ((Applet)this).getParameter("DOC");
- if (docString != null) {
- this.fIsSiteCamDoc = true;
- fileString = newBase + docString + (this.fSiteProxy ? ".sp" : ".mwc") + "?images=1";
- }
- }
-
- this.fLoadingString = ((Applet)this).getParameter("LOADSTRING");
- if (this.fLoadingString == null) {
- this.fLoadingString = "Initializing SiteCam...";
- }
-
- if (fileString == null) {
- this.fErrString = "no DOC or FILE specified.";
- } else {
- System.out.println("fileString " + fileString);
-
- try {
- this.fURL = new URL(fileString);
- System.out.println("SiteCamGrab fURL " + this.fURL.toString());
- } catch (Exception var7) {
- System.out.println(this.fErrString);
- this.fErrString = "SiteCam: Bad URL " + fileString;
- return;
- }
-
- if (((Applet)this).getParameter("images") != null) {
- this.fImagesToSend = Integer.parseInt(((Applet)this).getParameter("images"));
- }
-
- if (((Applet)this).getParameter("delay") != null) {
- this.fSleep = Integer.parseInt(((Applet)this).getParameter("delay"));
- }
-
- if (((Applet)this).getParameter("minutes") != null) {
- int minutes = Integer.parseInt(((Applet)this).getParameter("minutes"));
- this.fSleep += minutes * '\uea60';
- }
-
- if (((Applet)this).getParameter("seconds") != null) {
- int seconds = Integer.parseInt(((Applet)this).getParameter("seconds"));
- this.fSleep += seconds * 1000;
- }
-
- if (this.fDebug) {
- System.out.println("getFile " + this.fURL.getFile().toString());
- if (this.fURL.getRef() != null) {
- System.out.println("getRef " + this.fURL.getRef().toString());
- }
- }
-
- if (fileString == null) {
- this.fatalError("no DOC or FILE specified.");
- } else {
- this.fSleep = -1;
-
- try {
- if (((Applet)this).getParameter("delay") != null) {
- this.fSleep = Integer.parseInt(((Applet)this).getParameter("delay"));
- }
-
- if (((Applet)this).getParameter("minutes") != null) {
- int minutes = Integer.parseInt(((Applet)this).getParameter("minutes"));
- this.fSleep += minutes * '\uea60';
- }
-
- if (((Applet)this).getParameter("seconds") != null) {
- int seconds = Integer.parseInt(((Applet)this).getParameter("seconds"));
- this.fSleep += seconds * 1000;
- }
- } catch (Exception var6) {
- }
-
- if (this.fSleep == -1) {
- this.fSleep = this.fIsSiteCamDoc ? 100 : '\uea60';
- }
-
- if (this.fDebug) {
- System.out.println("Starting webcam... Interframe delay " + (double)this.fSleep / (double)1000.0F + " seconds");
- }
-
- this.fThread = new Thread(this);
- this.fThread.suspend();
- this.fThread.start();
- }
- }
- }
-
- public void paint(Graphics g) {
- if (this.fLastImage != null) {
- this.fGettingFirst = false;
- g.drawImage(this.fLastImage, 0, 0, (ImageObserver)null);
- } else {
- g.drawString(((Applet)this).getAppletInfo(), 10, 10);
- if (this.fErrString == null) {
- g.drawString("Loading…", 10, 30);
- } else {
- g.drawString(this.fErrString, 10, 30);
- }
- }
-
- }
-
- public void abort() throws Exception {
- this.fAbort = true;
-
- while(!this.fDone) {
- Thread.sleep(100L);
- }
-
- }
-
- public synchronized Image GetNextImage() {
- try {
- Image theImage = ((Applet)this).getImage(this.fURL);
- MediaTracker fMediaTracker = new MediaTracker(this);
- fMediaTracker.addImage(theImage, 1);
- fMediaTracker.waitForAll(120000L);
- if (fMediaTracker.isErrorID(1)) {
- System.out.println("SiteCamGrab fMediaTracker failed " + this.fURL.toString());
- this.fAbort = true;
- }
-
- return theImage;
- } catch (Exception e) {
- System.out.println("SiteCamGrab GetNextImage" + ((Throwable)e).toString() + " URL: " + this.fURL.toString());
- return null;
- }
- }
-
- protected synchronized void GetStreamingImages() throws Exception {
- System.out.println("GetStreamingImages");
-
- while(!this.fAbort) {
- Image img = this.GetNextImage();
- if (img == null) {
- this.fDone = true;
- this.fAbort = true;
- break;
- }
-
- if (this.fImage1 == null) {
- this.fImage1 = img;
- this.TakeImage(this.fImage1);
- if (this.fImage2 != null) {
- this.fImage2.flush();
- this.fImage2 = null;
- }
- } else if (this.fImage2 == null) {
- this.fImage2 = img;
- this.TakeImage(this.fImage2);
- if (this.fImage1 != null) {
- this.fImage1.flush();
- this.fImage1 = null;
- }
- } else {
- System.out.println("SiteCamGrab unexpected state 3.");
- this.fImage1.flush();
- this.fImage1 = img;
- this.TakeImage(this.fImage1);
- this.fImage2.flush();
- this.fImage2 = null;
- }
-
- if (this.fImagesToSend != -1 && this.fImagesSent >= this.fImagesToSend) {
- break;
- }
- }
-
- this.fDone = true;
- }
-
- public synchronized void TakeImage(Image inImage) {
- try {
- this.fLastImage = inImage;
- Graphics g = ((Component)this).getGraphics();
- this.paint(g);
- ++this.fImagesSent;
- } catch (Exception var3) {
- }
- }
- }
-